package com.ytktt.study.week12.task7.service;

import com.ytktt.study.week12.task7.entity.OrderEntity;
import com.ytktt.study.week12.task7.mapper.OrderMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicLong;

/**
 * TODO
 *
 * @author ytk
 */
@Service
@RequiredArgsConstructor
public class OrderServiceImpl implements OrderService {

    private final OrderMapper orderMapper;
    private final AtomicLong al = new AtomicLong(0);

    @Value("${taskRegion}")
    private int taskRegion;

    @Override
    public void providerOrder() {
        OrderEntity entity = new OrderEntity();
        long id = this.al.incrementAndGet();
        entity.setId(id);
        entity.setStatus((byte) 0);
        entity.setTaskRegion((int) (id % this.taskRegion) + 1);
        this.orderMapper.insertOrder(entity);
    }
}
